<template>
  <div class="app-container">
    <el-form ref="elFormSetting" :model="formSettingData" :rules="rules" size="medium" label-width="120px">

      <el-form-item label="媒体服务器主机地址" prop="media_host">
        <el-input
          v-model="formSettingData.media_host"
          placeholder="请输入媒体服务器主机地址"
          clearable
          :style="{width:'100%'}"
        />
      </el-form-item>
      <el-form-item label="http 端口号" prop="http_port">
        <el-input
          v-model="formSettingData.http_port"
          placeholder="http端口号"
          clearable
          :style="{width:'100%'}"
        />
      </el-form-item>
      <el-form-item label="https 端口号" prop="https_port">
        <el-input
          v-model="formSettingData.https_port"
          placeholder="https 端口号"
          clearable
          :style="{width:'100%'}"
        />
      </el-form-item>
      <el-form-item label="rtmp 端口号" prop="rtmp_port">
        <el-input
          v-model="formSettingData.rtmp_port"
          placeholder="rtmp 端口号"
          clearable
          :style="{width:'100%'}"
        />
      </el-form-item>
      <el-form-item label="rtp 端口号起" prop="rtmp_min_port">
        <el-input
          v-model="formSettingData.rtmp_min_port"
          placeholder="50000"
          clearable
          :style="{width:'100%'}"
        />
      </el-form-item>
      <el-form-item label="rtp 端口号止" prop="rtmp_max_port">
        <el-input
          v-model="formSettingData.rtmp_max_port"
          placeholder="50500"
          clearable
          :style="{width:'100%'}"
        />
      </el-form-item>      
      <el-form-item size="large">
        <el-button type="primary" :loading="loading" @click="submitForm">提交</el-button>
        <el-button @click="resetForm">重置</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
import { load } from '@/api/mediaserver'
export default {
  name: 'MediaServerSetting',
  components: {},
  props: [],
  data() {
    return {
      formSettingData: {
        server_id: undefined,
        media_host: undefined,
        http_port: 9094,
        https_port: 9096,
        rtmp_port: 9092,
        rtp_min_port: 50000,
        rtp_max_port: 50500
      },
      loading: false,
      rules: {
        media_host: [{ required: true, message: '请输入媒体服务器主机地址', trigger: 'blur' }],
        http_port: [{ required: true, message: '请输入媒体服务器http端口号', trigger: 'blur' }],
        https_port: [{ required: true, message: '请输入媒体服务器https端口号', trigger: 'blur' }],
        rtmp_port: [{ required: true, message: '请输入rtmp端口号', trigger: 'blur' }],
        rtp_min_port: [{ required: true, message: '请输入rtp起始端口', trigger: 'blur' }],
        rtp_max_port: [{ required: true, message: '请输入rtp结束端口', trigger: 'blur' }]
      }
    }
  },
  computed: {},
  watch: {},
  created() {
    this.fetchData()
  },
  mounted() {},
  methods: {
    fetchData() {
      load().then(ret => {
        console.log('ret.data', ret.data)
        this.formSettingData = ret.data
      })
    },
    submitForm() {
      this.$refs['elFormSetting'].validate(valid => {
        if (valid) {
          this.loading = true
          this.$store.dispatch('setting/save', this.formSettingData).then(() => {
            // this.$router.push({ path: this.redirect || '/' })
            this.loading = false
          }).catch((err) => {
            console.error(err)
            this.loading = false
          })
        } else {
          this.loading = false
        }
      })
    },
    resetForm() {
      this.$refs['elFormSetting'].resetFields()
    }
  }
}

</script>
<style>
</style>
